package com.sqx.modules.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.health.common.RoleEnum;
import com.sqx.modules.health.dto.UserPasswordDTO;
import com.sqx.modules.health.entity.Agent;
import com.sqx.modules.sys.entity.SysUserEntity;
import com.sqx.modules.health.entity.UserDevice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户信息	 Mapper 接口
 * </p>
 *
 * @author gxy
 * @since 2022-04-14
 */
public interface UserMapper extends BaseMapper<SysUserEntity> {

    @Update("update sys_user set password = #{newPassword} where username = #{username} and password = #{password}")
    boolean updatePassword(UserPasswordDTO userPasswordDTO);

    Object findPage(Page<Object> page, String username, String phone, String nickname);

    SysUserEntity findRole(Long loginId, RoleEnum roleUser);

    SysUserEntity findByOpenid(String openid);

    SysUserEntity searchUser(String openid);

    SysUserEntity findByPhone(String phone);

    SysUserEntity findByUid(String uid);

    SysUserEntity findByToken(String token);

    @Update("update sys_user set token = #{token} where user_id = #{user_id}")
    void updateToken(SysUserEntity user);

    @Select("select * from sys_user_device where uid = #{id}")
    List<UserDevice> getUserDevice(Long id);

    @Delete("delete from sys_user_device where uid = #{uid} and deviceid = #{deviceid}")
    void UserUnBinding(Long uid, Long deviceid);

    @Select("select * from health_sys_agent where uid = #{uid} or id = #{id}")
    List<Agent> findAllOperation(String uid, Long id);

    List<String> getResult(Long hid);
}
